home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
3_0
/
OIC_1
/
OIC_SOUR
/
STDIOSTR.C
< prev
next >
Wrap
Text File
|
1989-03-05
|
2KB
|
97 lines
/*
* StdioStream abstract class
*
* a kind of Stream that connects to the C library
* standard I/O
*
* Copyright ⌐ John Wainwright 1989
*
* SuperClasses :
* Stream
* Instance Vars :
*
* Class Vars :
*
* Methods :
*
* Class Methods :
*
*/
#include <stdio.h>
#include "oic.h"
#include "generics.h"
class StdioStream; /* the StdioStream class */
object screen; /* default standard i/o ... */
object error;
struct StdioStream_i /* StdioStream instance structure */
{
int fd; /* file descriptor */
char *name;
};
typedef struct StdioStream_i StdioStream_i;
/* -------------------- StdioStream Instance methods ------------------- */
static object
_new(self, s, ap) /* create a stdio stream */
object self;
register StdioStream_i *s;
register struct
{
char *name;
char *mode;
} *ap;
{
s->name = ap->name; /* dummy just now */
}
method object
_put(self, s, str) /* output string */
object self;
register StdioStream_i *s;
register char **str;
{
register char *p;
for (p = *str; *p; )
putchar(*p++);
}
method char *
_gprintf(self, s, ap) /* formatted print (printf) */
object self;
register StdioStream_i *s;
register struct
{
char *fmt;
double a1, a2, a3, a4, a5, a6,
a7, a8, a9;
} *ap;
{
char buf[512];
sprintf(buf, ap->fmt, ap->a1, ap->a2, ap->a3, ap->a4, ap->a5,
ap->a6, ap->a7, ap->a8, ap->a9);
put(self, buf);
}
/* ------------------- Init the StdioStream class ---------------------- */
InitStdioStream()
{
StdioStream = NewClass(sizeof(StdioStream_i), 0, "StdioStream", END);
AddMethods(StdioStream,
newGeneric, _new,
putGeneric, _put,
gprintfGeneric, _gprintf,
END);
screen = New(StdioStream, "screen");
error = New(StdioStream, "error");
}